package GUI;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 * This class the initialize port and ip for client
 * @author michael
 *
 */
public class ClientInitialize extends JFrame
{

	private JLabel portLabel = null;
	private JLabel ipLabel = null;
	private JTextField ipField = null;
	private JTextField portLabelField = null;
	private JButton startButton = null;
	private JPanel jContentPane = null;
	
	
	/**
	 * This is the default constructor
	 */
	public ClientInitialize() 
	{
		super();
		initialize();		
	}

	/**
	 * This method initializes AcademicFrame 
	 */
	private void initialize()
	{
		this.setSize(400, 300);
		this.setContentPane(getJContentPane());
		this.setTitle("CCRM CLIENT");		
	}
	/**
	 * This method initializes LoginForm
	 */
	private JPanel getJContentPane() 
	{
		if (jContentPane == null) 
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			portLabel  = new JLabel();
			portLabel .setBounds(new Rectangle(15, 30, 113, 22));
			portLabel .setText("Port");
			
			ipLabel  = new JLabel();
			ipLabel .setBounds(new Rectangle(15, 50, 113, 22));
			ipLabel .setText("IP");
						
			jContentPane.add(portLabel, null);
			jContentPane.add(ipLabel, null);
			jContentPane.add(getPortLabelField(), null);
			jContentPane.add(ipField(), null);
			jContentPane.add(getStartButton(),null);
		}
		return jContentPane;		
	}
	
	/**
	 * This method initializes portLabelField	
	 */
	private JTextField getPortLabelField()
	{
		if (portLabelField == null) 
		{
			portLabelField = new JTextField();
			portLabelField.setBounds(new Rectangle(80, 30, 130, 22));			
		}
		return portLabelField;
	}
	
	
	/**
	 * This method initializes my_SQLusernameField	
	 */
	private JTextField ipField()
	{
		if (ipField == null) 
		{
			ipField = new JTextField();
			ipField.setBounds(new Rectangle(80, 50, 130, 22));			
		}
		return ipField;
	}
	
	
	/**
	 * This method initializes startButton	
	 */
	public JButton getStartButton() 
	{
		if (startButton == null) 
		{
			startButton = new JButton();
			startButton.setBounds(new Rectangle(90, 90, 110, 29));
			startButton.setText("START");
		}	
		return startButton;
	}	
	 
	/**
	 *  This method return the entered port	
	 */
	public int getPort()
	{
		int port=0;
		String msg;
		try
		{
			if (portLabelField != null)
			{
				msg = portLabelField.getText();
				if (msg.equals(""))
					return 0;
				port = Integer.parseInt(msg);
			}	
			return port;
		}catch (Exception e)
		{
			return -1;
		}		
	}
	
	/**
	 *  This method return the entered port	
	 */
	public String getIP()
	{
		String ip = "";
		if (ipField != null)
		{
			ip = ipField.getText();
			if (ip.equals(""))
			{
				return "localhost";
			}
			else
				return ip;			
		}	
		return "localhost";
	}
	
	
	
	
	
	
}


